<?php
namespace app\api\controller;


use app\common\model\Articles;
use MoCommon\Support\Codes;

class Article extends Base
{
    public function dataList()
    {
        $page = input("page", 1);
        $artType = input("artType", 1);

        //获取列表数据
        $articleModel = new Articles();
        $where[] = ["article_type", "=", $artType];
        $dataList = $articleModel->dataList(Articles::class, $where, 2, $page, "is_top desc,id desc");
        $dataTotal = $articleModel->dataCount(Articles::class, $where);
        $status = Codes::ACTION_SUC;
        $message = Codes::get(Codes::ACTION_SUC);
        return json(["status" => $status, "msg" => $message, "data" => ["data" => $dataList, "total" => $dataTotal]]);
    }


    public function dataDetail()
    {
        $id=input("id",0);
        $articleModel = new Articles();
        //阅读量加一
        $articleModel->dataInc(Articles::class, ["id" => $id], "read_count");
        $status = Codes::ACTION_SUC;
        $message = Codes::get(Codes::ACTION_SUC);
        $detail = $articleModel->oneDetail(Articles::class, ["id" => $id]);
        $detail["article_msg"] = str_replace('src="/ueditor', 'src="' . config("app.web_config.web_url") . '/ueditor', $detail["article_msg"]);
        return json(["status" => $status, "msg" => $message, "data" => $detail]);
    }
}
